const Koa = require('koa');
const app = new Koa();

//1.处理静态资源
const static = require('koa-static');

const path = require('path');

//2.处理post请求传递的参数

const bodyparser = require('koa-bodyparser');

//3.路由 写接口

const router = require('./router');

const query = require('./middleware/query');

app.use(static(path.join(process.cwd(),'public')));


//静态资源和接口
app.use(bodyparser());  //ctx.request.body

app.use(query()); //ctx.mysql.query 

app.use(router.routes()); 

app.use(router.allowedMethods());

app.listen(process.env.PORT || 3000,() => {
    console.log("服务启动成功")
})